import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:oktoast/oktoast.dart';
import 'package:platform/platform.dart';
import 'package:video_setting/pages/api/base_api.dart';
import 'package:video_setting/pages/constant/app_constant.dart';
import 'package:video_setting/pages/router/router.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  SpUtil.getInstance();
  if (Platform.android.isNotEmpty) {
    var systemUiOverlayStyle = const SystemUiOverlayStyle(statusBarColor: Colors.transparent);
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);

    /// 强制竖屏
    SystemChrome.setPreferredOrientations([DeviceOrientation.portraitDown, DeviceOrientation.portraitUp]).then((_) {
      runApp(const MyApp());
    });
  } else {
    runApp(const MyApp());
  }
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    BaseApi.initDio(AppConstant.BASE_API);
    return OKToast(
        child: GetMaterialApp(
      title: AppConstant.APP_TITLE,
      debugShowCheckedModeBanner: false,
      defaultTransition: Transition.rightToLeft,
      builder: (context, child) => Scaffold(
        body: GestureDetector(
          child: child,
          onTap: () {},
        ),
        resizeToAvoidBottomInset: false,
      ),
      getPages: Routers.routes,
      initialRoute: Routers.ViewSetting,
    ));
  }
}

// 收回键盘
void closeKeyBoard() {
  // 触摸收起键盘（方式一）
  var currentFocus = FocusScope.of(Get.context!);
  if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
    FocusManager.instance.primaryFocus?.unfocus();
  }
  // 触摸收起键盘（方式二）
  // FocusScope.of(context).requestFocus(FocusNode());
}
